package com.ruoyi.gcgl.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.gcgl.domain.GysptWarehouse;
import com.ruoyi.gcgl.mapper.GysptWarehouseMapper;
import com.ruoyi.gcgl.service.IGysptWarehouseService;

/**
 * 库存管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-01
 */
@Service
public class GysptWarehouseServiceImpl implements IGysptWarehouseService 
{
    @Autowired
    private GysptWarehouseMapper gysptWarehouseMapper;

    /**
     * 查询库存管理
     * 
     * @param id 库存管理主键
     * @return 库存管理
     */
    @Override
    public GysptWarehouse selectGysptWarehouseById(Long id)
    {
        return gysptWarehouseMapper.selectGysptWarehouseById(id);
    }

    /**
     * 查询库存管理列表
     * 
     * @param gysptWarehouse 库存管理
     * @return 库存管理
     */
    @Override
    public List<GysptWarehouse> selectGysptWarehouseList(GysptWarehouse gysptWarehouse)
    {
        return gysptWarehouseMapper.selectGysptWarehouseList(gysptWarehouse);
    }

    /**
     * 新增库存管理
     * 
     * @param gysptWarehouse 库存管理
     * @return 结果
     */
    @Override
    public int insertGysptWarehouse(GysptWarehouse gysptWarehouse)
    {
        return gysptWarehouseMapper.insertGysptWarehouse(gysptWarehouse);
    }

    /**
     * 修改库存管理
     * 
     * @param gysptWarehouse 库存管理
     * @return 结果
     */
    @Override
    public int updateGysptWarehouse(GysptWarehouse gysptWarehouse)
    {
        return gysptWarehouseMapper.updateGysptWarehouse(gysptWarehouse);
    }

    /**
     * 批量删除库存管理
     * 
     * @param ids 需要删除的库存管理主键
     * @return 结果
     */
    @Override
    public int deleteGysptWarehouseByIds(String ids)
    {
        return gysptWarehouseMapper.deleteGysptWarehouseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除库存管理信息
     * 
     * @param id 库存管理主键
     * @return 结果
     */
    @Override
    public int deleteGysptWarehouseById(Long id)
    {
        return gysptWarehouseMapper.deleteGysptWarehouseById(id);
    }

	@Override
	@DataScope(deptAlias = "d")
	public List<Ztree> selectWarehouseTree(GysptWarehouse warehouse) {
		// TODO Auto-generated method stub
		List<GysptWarehouse> typeList =  gysptWarehouseMapper.selectGysptWarehouseList(warehouse);
		List<Ztree> ztrees = initZtree(typeList);
		return ztrees;
	}
	
	/**
     * 对象转部门树
     *
     * @param deptList 部门列表
     * @return 树结构列表
     */
    public List<Ztree> initZtree(List<GysptWarehouse> deptList)
    {
        return initZtree(deptList, null);
    }
    
    /**
     * 对象转部门树
     *
     * @param deptList 部门列表
     * @param roleDeptList 角色已存在菜单列表
     * @return 树结构列表
     */
    public List<Ztree> initZtree(List<GysptWarehouse> typeList, List<String> roleDeptList){
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (GysptWarehouse type : typeList){
            Ztree ztree = new Ztree();
            ztree.setId(type.getId());
            ztree.setpId(type.getpId());
            ztree.setName(type.getName());
            ztree.setTitle(type.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}